package com.factory.iamp.utils.helper;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.factory.iamp.utils.exception.APIException;

import java.util.ArrayList;
import java.util.LinkedHashMap;

public class SetMethodHelper {
    public static String SetString(Object value) {
        if(value instanceof JSONArray) return JSONArray.toJSONString(value);
        if(value instanceof ArrayList) return JSONArray.toJSONString(value);
        if(value instanceof String) return (String) value;
        if(value instanceof JSONObject) return JSONArray.toJSONString(value);
        if(value instanceof LinkedHashMap) return JSONObject.toJSON(value).toString();
        throw new APIException(ResponseCode.ERROR, "数据转换失败: from " + value.getClass() + " to String");
    }
}
